package com.neutech.controller;

import com.google.gson.Gson;

import com.neutech.service.FoodService;
import com.neutech.service.impl.FoodServiceImpl;
import com.neutech.vo.ResultVO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/business/foods")
public class FoodListByBusinessIdServlet extends HttpServlet {

    protected FoodService foodService = new FoodServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String businessId = req.getParameter("businessId");
        PrintWriter out = resp.getWriter();
        Gson gson = new Gson();

        if (businessId == null) {
            out.print(ResultVO.error(1001,"商家ID不能为空"));
            out.close();
            return;
        }

        out.print(gson.toJson(foodService.listFoodByBusinessId(Integer.parseInt(businessId))));
    }
}
